package pro.cherish.knowledgerabbitmqproducer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 创建人：lys
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2020-3-22 lys 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：QueneConfig
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2020-3-22
 */
@Configuration
public class QueueConfig {

    public static final String CHERISH_TOPIC_EXCHANGE = "cherish_topic_exchange";
    public static final String CHERISH_DIRECT_EXCHANGE = "cherish_direct_exchange";
    public static final String QUENE_A = "quene_a";
    public static final String QUENE_B = "quene_b";
    public static final String QUENE_C = "quene_c";

    @Bean
    public Queue queueA() {
        return new Queue(QUENE_A);
    }

    @Bean
    public Queue queueB() {
        return new Queue(QUENE_B);
    }

    @Bean
    public Queue queueC() {
        return new Queue(QUENE_C);
    }

    @Bean
    public TopicExchange cherishTopicExchange() {
        return new TopicExchange(CHERISH_TOPIC_EXCHANGE);
    }
    @Bean
    public DirectExchange cherishDirecExchange() {
        return new DirectExchange(CHERISH_DIRECT_EXCHANGE);
    }

    public static final String CHERISH_ROUTE_KEY = "cherish.route.key";
    public static final String CHERISH_ROUTE_KEY_A = "cherish.*.key";
    public static final String CHERISH_ROUTE_KEY_B = "cherish.route.*";
    public static final String CHERISH_ROUTE_KEY_C = "cherish.*.*";
    /**
     * A、B、C是三个队列都绑定到cherish交换机（topic模式）上，路由键都是cherish.route.key，也就是说可以使用通配路由键，但是此处没有，而是精准匹配
     *
     */
    @Bean
    public Binding bindingA() {
        return BindingBuilder.bind(queueA()).to(cherishTopicExchange()).with(CHERISH_ROUTE_KEY_A);
    }

    @Bean
    public Binding bindingB() {
        return BindingBuilder.bind(queueB()).to(cherishTopicExchange()).with(CHERISH_ROUTE_KEY_B);
    }

    @Bean
    public Binding bindingC() {
        return BindingBuilder.bind(queueC()).to(cherishTopicExchange()).with(CHERISH_ROUTE_KEY_C);
    }



}
